<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>获取验证码</title>
    <style>
      input {
        outline: none;
      }

      button {
        margin-left: 5px;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div class="box">手机号：<input type="number" /><button>获取验证码</button></div>

    <script>
      var btn = document.querySelector('button');
      var time = 60;

      btn.onclick = function () {
        btn.disabled = true;
        var timer = setInterval(function () {
          if (time === 0) {
            clearInterval(timer);
            btn.disabled = false;
            btn.innerHTML = '获取验证码';
            time = 60; // 注意：这里需要重置秒数
          } else {
            btn.innerHTML = '还剩下' + time + '秒';
            time--;
          }
        }, 1000);
      };
    </script>
  </body>
</html>
